<template>
  <el-dialog
    title="导入需求计划"
    :visible.sync="dialogTableVisible"
    :close-on-click-modal="false"
    width="1000px"
  >
    <el-form>
      <el-form-item label="计划月份" prop="planMonth">
        <el-date-picker
          v-model="planMonth"
          @change="getMessage"
          type="month"
          size="small"
          format="yyyy-MM"
          value-format="yyyy-MM"
          :placeholder='getCurrentTime'
        ></el-date-picker>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogTableVisible = false">取消</el-button>
      <el-button type="primary" size="small" @click="drXQmessage">确 定</el-button>
    </span>
    <el-table  :data="roleList" stripe
     @selection-change="xqSelectionChange"
      >
        <el-table-column align="center" type="selection" width="80"></el-table-column>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="需求计划名称"   property="pickName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label=" 资金来源名称"   property="moneySourceName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="金额/元"  property="totalAmount"  ></el-table-column>
      <el-table-column align="center" label="计划号" property="planNum" :show-overflow-tooltip="true"  ></el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "historyXQ",
  data() {
    return {
      planMonth: "",
      dialogTableVisible: true,
      roleList:[],
      //需求计划导入
      xqList:[],
      //计划导入的id
      xqListid:[],
      //上个月份
      beforeMonth:''
    };
  },
  created () {
    // this.getCurrentTime();
    this.getBMonthMessage()
  },
  computed:{
     getCurrentTime:function() { 
      beforeMonth = ''
      let currentTime = new Date(), 
      year = currentTime.getFullYear(),
      month = currentTime.getMonth()< 10 ? '0' + (currentTime.getMonth()) : currentTime.getMonth(),            
      beforeMonth = year + "-" + month
      console.log(beforeMonth)
      return beforeMonth
     },
  },
  methods: {
    getMessage(){
        console.log(this.planMonth)
      request({
        url: "/system/demandPlan/list?planMonth=" +this.planMonth+'&auditSteps=6',
        method: "get",
      }).then((response) => {
        console.log(response);
        this.roleList = response.rows
      });
    },
    getBMonthMessage () {
      request({
        url: "/system/demandPlan/list?planMonth=" +this.getCurrentTime+'&auditSteps=6',
        method: "get",
      }).then((response) => {
        console.log('获取上个月份历史需求')
        console.log(response);
        this.roleList = response.rows
      });
    },
    // getCurrentTime() { 
    //   beforeMonth = ''
    //   let currentTime = new Date(), 
    //   year = currentTime.getFullYear(),
    //   month = currentTime.getMonth()< 10 ? '0' + (currentTime.getMonth()) : currentTime.getMonth(),            
    //   beforeMonth = year + "-" + month
    //   console.log(beforeMonth)
    //   return beforeMonth
    //  },
    drXQmessage () {
      this.xqList.forEach(item =>{
        this.xqListid.push(item.id)
      })
      this.xqListid.toString()
      console.log(this.xqListid)
      request({
          url:'/system/info/listByMouthHistory?ids='+this.xqListid,
          method: 'get'
      }).then(response =>{
          console.log(response)
          this.$emit('xqHistoryme',response.data)
          this.dialogTableVisible = false
      })
    },
    xqSelectionChange (row) {
      this.xqList = row
       console.log('导入需求计划',this.xqList)
    }
  },
};
</script>